using Cheng;
using Cheng.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
using GameEntry = Cheng.GameEntry;

public class DialogForm : UGuiForm
{
    /*声明*/
	private Image _dialogBackGroud;
	private Text _textEx;
	private Text _message;
	private Button _confirmBtn;
	private Button _cancelBtn;
	private DialogParams dialog;
	protected override void OnInit(object userData)
    {
        base.OnInit(userData);
		/*绑定*/
		
		_dialogBackGroud = transform.Find("DialogBackGroud").GetComponent<Image>();
		_textEx = transform.Find("TextEx").GetComponent<Text>();
		_message = transform.Find("Message").GetComponent<Text>();
		_confirmBtn = transform.FindComponent_BFS<Button>("ConfirmBtn");
		_cancelBtn = transform.FindComponent_BFS<Button>("CancelBtn");
        /*绑定方法*/
		
		
		
		_confirmBtn.AddClickMethod(On_ConfirmBtnClicked);
		_cancelBtn.AddClickMethod(On_CancelBtnClicked);
		/*接收消息*/
		

	}

    protected override void OnOpen(object userData)
    {
        base.OnOpen(userData);
		dialog = (DialogParams)userData;
		UpdateDialog();
	}

    private void UpdateDialog()
    {
		_textEx.text = (dialog).Title;
		_message.text = (dialog).Message;
        switch (dialog.Mode)
        {
			//case 1:
			//	_confirmBtn.text().text = dialog.ConfirmText;
			//	_cancelBtn.gameObject.SetActive(false);
			//	break;
			//case 2:
			//	_confirmBtn.text().text = dialog.ConfirmText;
			//	_cancelBtn.text().text = dialog.CancelText;
			//	_confirmBtn.gameObject.SetActive(true);
			//	_cancelBtn.gameObject.SetActive(true);
			//	break;
		}

    }

    /*方法*/



    //_confirmBtn按下时调用此方法
    private void On_ConfirmBtnClicked(GameObject game)
	{
		//TODO:添加自己的代码
		dialog.OnClickConfirm?.Invoke(game);
		GameEntry.UI.CloseUIForm(UIFormId.DialogForm);
	}

	//_cancelBtn按下时调用此方法
	private void On_CancelBtnClicked(GameObject game)
	{
		//TODO:添加自己的代码
		//Debug.Log("点击了"+ game.name+"按钮"); 
		dialog.OnClickCancel?.Invoke(game);
		GameEntry.UI.CloseUIForm(UIFormId.DialogForm);
	}

}
